package com.hjqjl.whdemo.feature.feature0.ui.activity.custom;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.hjqjl.whdemo.base.BaseActivity;
import com.hjqjl.whdemo.databinding.ActivityCountDownBinding;
import com.hjqjl.whdemo.widget.CountDownButtonHelper;

/**
 * 倒计时按钮
 */
public class CountDownActivity extends BaseActivity {
    public static void actionStart(Context context) {
        Intent intent = new Intent(context, CountDownActivity.class);
        context.startActivity(intent);
    }

    private CountDownButtonHelper countDownButtonHelper;
    private ActivityCountDownBinding binding;

    @Override
    protected void initData() {
        binding = ActivityCountDownBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        countDownButtonHelper = new CountDownButtonHelper(binding.btnCountDown);
    }

    @Override
    protected void processLogic() {
        binding.btnCountDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countDownButtonHelper.start();
            }
        });
        countDownButtonHelper.setOnFinishListener(new CountDownButtonHelper.OnFinishListener() {
            @Override
            public void finish() {
                com.blankj.utilcode.util.ToastUtils.showShort("倒计时结束调用");
            }
        });
    }

    @Override
    protected void onDestroy() {
        if (null != countDownButtonHelper) {
            countDownButtonHelper.cancel();
        }
        super.onDestroy();
    }
}
